/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.manusoft.refill.domain;

import java.util.List;
import java.util.Map;

import org.manusoft.refill.service.DriverService;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

/**
 *
 * @author levent
 */
public class MyLazyDriverDataModel extends LazyDataModel<TDriverDetailsRf> {

    
    private DriverService driverService;
    
    private Map<String, String> filters;

    public DriverService getService() {
        return driverService;
    }

    public void setService(DriverService vehicleService) {
        this.driverService = vehicleService;
    }

    @Override
    public int getRowCount() {
        return driverService.getRowCount(filters).intValue();
    }
    
    @Override
    public List<TDriverDetailsRf> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) {
        
        //store data filters
        this.filters = filters;
        
        return getService().loadLazy(first, pageSize, sortField, sortOrder, filters);
    }
    
    public MyLazyDriverDataModel(DriverService vehicleService){
        setService(vehicleService);
    }
    
    @Override
    public Object getRowKey(TDriverDetailsRf driverDetails) {
        return driverDetails.getDriverId();
    }
    
    @Override
    public TDriverDetailsRf  getRowData(String rowKey) {
        return driverService.findById(Integer.parseInt(rowKey),false);
    }
}
